package com.example.administrator.myapplication;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.example.administrator.myapplication.chat.Print;

/**
 * Created by Administrator on 2018/11/21.
 */

public class Mservice extends Service {
    int anInt;
    boolean aBoolean=true;
    Mbinder mbinder=new Mbinder();
    public class Mbinder extends Binder{
        public int getInt(){
            return anInt;
        }
    }
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Print.string("onBind  被调用");
        return mbinder;
    }

    @Override
    public void onCreate() {
        Print.string("onCreat 创建 调用");
        super.onCreate();

        new Thread(){
            @Override
            public void run() {
                super.run();
                while (aBoolean){
                    try {
                        Thread.sleep(2000);
                        anInt++;
                        Print.string("on___"+anInt);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Print.string("onStartCommand  启动 调用");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Print.string("onUnbind  断开连接  回调");
        return super.onUnbind(intent);
    }

    @Override
    public void onDestroy() {
        aBoolean=false;
        Print.string("onDestroy  关闭前 调用");
        super.onDestroy();
    }

    @Override
    public void onRebind(Intent intent) {
        Print.string("onRebing  调用");
        super.onRebind(intent);
    }
}
